package s47.dqj.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import s47.dqj.bean.PatientMedicalPrice;

/**
 * 23.患者药品总价表（总订单）
 * @author Administrator
 *
 */
@Repository("patientMedicalPriceDaoImpl")
public class PatientMedicalPriceDaoImpl extends HibernateDaoSupport implements PatientMedicalPriceDaoInf{
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientMedicalPriceDaoInf#setSupperSessionFactory(org.hibernate.SessionFactory)
	 */
	@Override
	@Resource(name="sessionFactory")
	public void setSupperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientMedicalPriceDaoInf#findAllByCondition(java.lang.String, java.lang.Integer)
	 */
	@Override
	public List<PatientMedicalPrice> findAllByCondition(String hql,Integer pageNum){
		Query query=getSession().createQuery(hql);
		query.setFirstResult((Integer.valueOf(pageNum)-1)*20);
		query.setMaxResults(20);
		return query.list(); 
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientMedicalPriceDaoInf#selectPageTotal(java.lang.String)
	 */
	@Override
	public List<Integer> selectPageTotal(String tempHQL){
		List<Integer> pageTotal=new ArrayList<Integer>();
		int p;
		Long temp;
		String hql="select Count(*) from PatientMedicalPrice as pmp"+tempHQL;
		Query query=getSession().createQuery(hql);
		temp=(Long)query.uniqueResult();
		
		if(temp%20!=0)
			p=(int)(temp/20+1);
		else
			p=(int)(temp/20);
		for(int n=0;n<p;n++){
			pageTotal.add(n+1);
		}
		return pageTotal;
	} 
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientMedicalPriceDaoInf#save(s47.dqj.bean.PatientMedicalPrice)
	 */
	@Override
	public void save(PatientMedicalPrice patientMedicalPrice){
		getHibernateTemplate().save(patientMedicalPrice);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientMedicalPriceDaoInf#update(s47.dqj.bean.PatientMedicalPrice)
	 */
	@Override
	public void update(PatientMedicalPrice patientMedicalPrice){
		getHibernateTemplate().update(patientMedicalPrice);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientMedicalPriceDaoInf#delete(s47.dqj.bean.PatientMedicalPrice)
	 */
	@Override
	public void delete(PatientMedicalPrice patientMedicalPrice){
		getHibernateTemplate().delete(patientMedicalPrice);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientMedicalPriceDaoInf#findObject(s47.dqj.bean.PatientMedicalPrice)
	 */
	@Override
	public PatientMedicalPrice findObject (PatientMedicalPrice patientMedicalPrice){
		return getHibernateTemplate().get(PatientMedicalPrice.class,patientMedicalPrice.getPmpid());
	}
	
}
